home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / loTeX / loTeX.app / XText0.m < prev    next >
Encoding:
Text File  |  1992-04-14  |  2.8 KB  |  139 lines

  1. /*    This file is part of the XText package (version 0.8)
  2.     Mike Dixon, April 1992
  3.     
  4.     Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  5.  
  6.     Use and copying of this software and preparation of derivative works based
  7.     upon this software are permitted.  This software is made available AS IS,
  8.     and Xerox Corporation makes no warranty about the software or its
  9.     performance.
  10. */
  11.  
  12. #import "XText0.h"
  13. #import "XTAction.h"
  14. #import "ErrorStream.h"
  15. #import <objc/objc.h>
  16. #import <appkit/Window.h>
  17. #import <appkit/publicWraps.h>
  18.  
  19. @implementation XText0
  20.  
  21. struct WindowGuts { @defs(Window); }; 
  22.  
  23. /*    everything except the setInitialAction/setErrorStream is copied straight
  24.     out of Window's getFieldEditor:for: method
  25. */
  26.  
  27. + newFieldEditorFor:win initialAction:action estream:errs
  28. {
  29.     id editor = nil;
  30.     
  31.     if ([win isKindOf: [Window class]]) {
  32.         editor = ((struct WindowGuts *)win)->fieldEditor;
  33.         if (editor == nil) {
  34.             editor = [[self allocFromZone:[win zone]] init];
  35.             [editor setCharFilter: &NXFieldFilter];
  36.             [editor setSelectable: YES];
  37.             [editor setFontPanelEnabled: NO];
  38.             [editor setInitialAction:action];
  39.             if (errs)
  40.                 [editor setErrorStream:errs];
  41.             ((struct WindowGuts *)win)->fieldEditor = editor;
  42.         }
  43.     }
  44.     return editor;
  45. }
  46.  
  47. - initFrame:(const NXRect *)frameRect text:(const char *)theText
  48.     alignment:(int)mode
  49. {
  50.     [super initFrame:frameRect text:theText alignment:mode];
  51.     nextAction = nil;
  52.     initialAction = nil;
  53.     errorStream = [ErrorStream default];
  54.     return self;
  55. }
  56.  
  57. /*    We want to make sure that unrecognized messages are reported nicely,
  58.     since it's easy to generate them while your experimenting.
  59. */
  60.  
  61. - doesNotRecognize:(SEL)sel
  62. {
  63.     char msg[100];
  64.  
  65.     sprintf(msg, "No method for %.48s on this text object", sel_getName(sel));
  66.     [errorStream report: msg];
  67.     return self;
  68. }
  69.  
  70. /*    Egregious paranoia: don't set the error stream to something that can't
  71.     report errors...
  72. */
  73.  
  74. - setErrorStream:errs
  75. {
  76.     if ([errs respondsTo: @selector(report:)])
  77.         errorStream = errs;
  78.     else
  79.         [errorStream report:"Invalid argument to setErrorStream:"];
  80.     return self;
  81. }
  82.  
  83. - errorStream
  84. {
  85.     return errorStream;
  86. }
  87.  
  88. - setInitialAction:action
  89. {
  90.     initialAction = nextAction = action;
  91.     return self;
  92. }
  93.  
  94. - initialAction
  95. {
  96.     return initialAction;
  97. }
  98.  
  99. - setNextAction:action
  100. {
  101.     nextAction = action;
  102.     return self;
  103. }
  104.  
  105. - keyDown:(NXEvent *)event
  106. {
  107.     id temp;
  108.  
  109.     temp = nextAction;
  110.     nextAction = initialAction;
  111.     if (temp) {
  112.         temp = [temp applyTo:self event:event];
  113.         if (vFlags.disableAutodisplay) {
  114.             [self setAutodisplay:YES];
  115.             [self display];
  116.         }
  117.         if (sp0.cp == spN.cp)
  118.             [self setSel:sp0.cp :sp0.cp];    // hack to make caret reappear
  119.     }
  120.     return temp ? self : [super keyDown:event];
  121. }
  122.  
  123. - unboundKey
  124. {
  125.     NXBeep();
  126.     return self;
  127. }
  128.  
  129. - disableAutodisplay
  130. {
  131.     // There seems to be a bug with turning off autodisplay in text fields,
  132.     // so try to avoid doing it.
  133.     if (charFilterFunc != &NXFieldFilter)
  134.         [self setAutodisplay:NO];
  135.     return self;
  136. }
  137.  
  138. @end
  139.